/*
 * @Description: log for JavaScript 配置
 * @Author: kanglin
 * @Date: 2018-09-26 16:20:34
 * @Copyright: Created by Panxsoft.
 */
const log4js = require('log4js');
const config = require('../config');

/** *
 * @see https://log4js-node.github.io/log4js-node/file.html
 */
log4js.configure({
	appenders: {
		serverEnd: {
			type: 'dateFile', // // 需要手动建好目录
			filename: `${config.logOutputDir}/node-server-`,
			pattern: 'yyyy-MM-dd.log',
			maxLogSize: 10 * 1000 * 1000, // 文件
			encoding: 'utf-8', // default "utf-8"，文件的编码
			// backups: 5, // 默认为5，指定了pattern之后backups参数无效了
			alwaysIncludePattern: true, // 不指定pattern时若为true会使用默认值'.yyyy-MM-dd'
		},
		clientEnd: {
			type: 'dateFile', // // 需要手动建好目录
			filename: `${config.logOutputDir}/client-`,
			pattern: 'yyyy-MM-dd.log',
			maxLogSize: 10 * 1000 * 1000, // 文件
			encoding: 'utf-8', // default "utf-8"，文件的编码
			// backups: 5, // 默认为5，指定了pattern之后backups参数无效了
			alwaysIncludePattern: true, // 不指定pattern时若为true会使用默认值'.yyyy-MM-dd'
			layout: { type: 'messagePassThrough' },
		},
	},
	categories: {
		default: { appenders: ['clientEnd'], level: 'info' }, // 必须的
		serverEnd: { appenders: ['serverEnd'], level: 'info' }, // node 服务日志配置
		clientEnd: { appenders: ['clientEnd'], level: 'info' }, // 客户端错误日志配置
	},
});

const severEndLogger = log4js.getLogger('serverEnd');
const clientEndLogger = log4js.getLogger('clientEnd');

module.exports = {
	severEndLogger,
	clientEndLogger,
};
